﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Skyhook.Sprites
{
    public static class SpriteParts
    {
        public const int Left = 0;
        public const int Right = 1;
    }
    internal class SpriteCenterDividedRenderer : ISpriteRenderer
    {
        int Part = 0;
        public SpriteCenterDividedRenderer(int part)
        {
            Part = part;
        }
        public void Render(SpriteBatch batch, Sprite sprite, Point position, Color color, float depth)
        {
            Vector2 vposition = new Vector2(position.X,position.Y);
            Rectangle texturerect = new Rectangle();
            Vector2 centerpoint = new Vector2();
            if (Part == SpriteParts.Left)
            {
                texturerect = new Rectangle(0, 0, (int)sprite.CenterPoint.X, sprite.TextureRectangle.Height);
                centerpoint = new Vector2(sprite.CenterPoint.X, sprite.CenterPoint.Y);
            }
            if (Part == SpriteParts.Right)
            {
                texturerect = new Rectangle((int)sprite.CenterPoint.X, 0, sprite.TextureRectangle.Width - (int)sprite.CenterPoint.X, sprite.TextureRectangle.Height);
                centerpoint = new Vector2(0, sprite.CenterPoint.Y);
            }
            batch.Draw(sprite.Texture, vposition - centerpoint, texturerect, color, 0, new Vector2(0, 0), 1.0f, SpriteEffects.None, depth); 
        }
    }
}
